package controls;

import java.util.Observable;
import java.util.Observer;

import models.ClienteLink;
import models.EstServicoLink;
import models.ModServicoLink;
import models.ServicoTNode;
import models.VeiculoTNode;
import views.PanFunVerServico;
import views.WinFuncionario;

public class ControllerFunVerServico implements Observer{
	private PanFunVerServico pan_fun_ver_serv;
	private WinFuncionario winFuncionario;
	private ServicoTNode servTNode;
	private ClienteLink clienteLink;
	private VeiculoTNode veicTNode;
	
	public void setPanel(ServicoTNode mynode, WinFuncionario windowFuncionario){
		winFuncionario = windowFuncionario;
		servTNode = mynode;
		veicTNode = (VeiculoTNode) ControllerLogin.getPersistence().find("VeiculoTree", servTNode.getVeiculoId());
		clienteLink = (ClienteLink) ControllerLogin.getPersistence().find("UsuarioLinkListInt", veicTNode.getClienteId());
		
		
		pan_fun_ver_serv = new PanFunVerServico();
		pan_fun_ver_serv.criaPanel();
		pan_fun_ver_serv.addObserver(this);
		
		pan_fun_ver_serv.setServicoId(Integer.toString(servTNode.getServicoId()));
		pan_fun_ver_serv.setNomeCliente(clienteLink.getNome());
		pan_fun_ver_serv.setVeiculoId(String.valueOf(servTNode.getVeiculoId()));
		pan_fun_ver_serv.setModServico(((ModServicoLink) ControllerLogin.getPersistence().find("ModServicoLinkList", servTNode.getModServicoId())).getNome());
		pan_fun_ver_serv.setEstServico(((EstServicoLink) ControllerLogin.getPersistence().find("EstServicoLinkList", servTNode.getEstServicoId())).getNome());
		pan_fun_ver_serv.setData(servTNode.getData());
		pan_fun_ver_serv.setRelatorio(servTNode.getRelatorio());
		pan_fun_ver_serv.setValor(String.valueOf(servTNode.getValor()));
		pan_fun_ver_serv.setGarantia(String.valueOf(servTNode.getGarantia()));
	
		winFuncionario.setContent(pan_fun_ver_serv.getPanel());
	}

	@Override
	public void update(Observable arg0, Object arg1) {
		String action = new String ((String) arg1);
		if(action.compareTo("EditarServico")==0){
			ControllerFunEditarServico editServ = new ControllerFunEditarServico();
			editServ.setPanel(servTNode, winFuncionario);
		}
		
		if(action.compareTo("AddPeca")==0){
			
		}
	}
}